package com.whh.utils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class BeanUtils extends StrUtils {

	public static void setValue(Object obj,String key,Object value) {
		String methodName = "set" + StrUtils.upperCaseFirst(key);  
        Method[] methods = obj.getClass().getMethods();
        try {
	        for (Method method : methods) {  
	            if (methodName.equals(method.getName())) {  
	                Class<?>[] clazz = method.getParameterTypes();  
	                String type = clazz[0].getName();  
	                if(type.equals("java.lang.String")){  
	                	method.invoke(obj,StrUtils.toStr(value)); 
	                }  
	                else if(type.equals("java.util.Date")){  
	                    method.invoke(obj, DateUtils.toDate(StrUtils.toStr(value)));  
	                }  
	                else if(type.equals("java.lang.Integer")){  
	                    method.invoke(obj, StrUtils.toInteger(value));  
	                }else{  
	                    //........  
	                }  
	            }  
	        }  
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}
}
